package com.kyzh.core.activities

import android.os.Bundle
import android.view.View
import android.widget.TextView
import androidx.recyclerview.widget.LinearLayoutManager
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.gushenge.core.base.activity.BaseActivity
import com.gushenge.core.beans.TiedMoney
import com.gushenge.core.impls.UserImpl
import com.gushenge.core.listeners.ResultListener
import com.kyzh.core.R
import kotlinx.android.synthetic.main.activity_tiedmoney.*
import kotlinx.android.synthetic.main.titlebar.*
import org.jetbrains.anko.toast

class TiedMoneyActivity : BaseActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_tiedmoney)
        initView()
    }

    private fun initView() {
        initUi()
        addData()
    }

    private fun addData() {
        UserImpl.tiedMoney(object : ResultListener {
            override fun success(bean: Any) {
                recyclerView.adapter = InnerAdapter(R.layout.point_detail_item, bean as ArrayList<TiedMoney>)
            }

            override fun error(error: String) {
                toast(error)
            }
        })
    }

    private fun initUi() {
        tvTime.text = getString(R.string.tiedMoney1)
        tvPoint.text = getString(R.string.tiedMoneyBanlance)
        tvTitle.text = getString(R.string.myTiedMoney)
        close.setOnClickListener { finish() }
        recyclerView.layoutManager = LinearLayoutManager(this@TiedMoneyActivity)
    }

    private inner class InnerAdapter(layout: Int, beans: ArrayList<TiedMoney>) : BaseQuickAdapter<TiedMoney, BaseViewHolder>(layout, beans) {
        override fun convert(helper: BaseViewHolder, item: TiedMoney) {
            helper.getView<TextView>(R.id.tv3).visibility = View.GONE
            helper.getView<TextView>(R.id.tv1).text = item.gname
            helper.getView<TextView>(R.id.tv2).text = item.bind_coin
        }
    }

}
